package com.cgl.mapper;

import com.cgl.pojo.LeaveMessage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LeaveMessageMapper {
    @Insert("insert into leave_message(ip,userName,createdTime,status,content,backcolor) values(#{ip},#{userName},#{createdTime},#{status},#{content},#{backcolor})")
    int addLeaveMessage(LeaveMessage leaveMessage);
    @Select("select count(*) from leave_message")
    int getAllConunt();
    @Select("SELECT lm.id, lm.ip, lm.content, lm.createdTime, lm.status, lm.backcolor, u.username AS userName " +
            "FROM leave_message lm " +
            "LEFT JOIN user u ON lm.userName = u.id " +
            "ORDER BY lm.createdTime DESC " +
            "LIMIT #{start}, #{end}")
    List<LeaveMessage> getAllLeaveMessageByPage(int start, int end);

    @Select("SELECT lm.id, lm.ip, lm.content, lm.createdTime, lm.status, lm.backcolor, u.username AS userName " +
            "FROM leave_message lm " +
            "LEFT JOIN user u ON lm.userName = u.id " +
            "ORDER BY lm.createdTime DESC")
    List<LeaveMessage> getAllLeaveMessage();
}
